<?php
require_once dirname(__FILE__).'/../lib/BaseCommentActions.class.php';

/**
 * event actions.
 *
 * @package    cpfaizenay
 * @subpackage event
 * @author     Manu
 * @version    1.0
 */
class commentActions extends BaseCommentActions
{
  public function executeReporting(sfWebRequest $request){
      
      isicsBreadcrumbs::getInstance()->addItem('Reporter ce commentaire', '#');
      $response = $this->getResponse();
      Utils::setSlogTitle('Reporter ce commentaire', $response);

      parent::executeReporting($request);
  }

  public function executeReported(sfWebRequest $request){
      isicsBreadcrumbs::getInstance()->addItem('Commentaire reporté', '#');
      $response = $this->getResponse();
      Utils::setSlogTitle('Commentaire reporté', $response);

      parent::executeReported($request);
  }

 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeEdit(sfWebRequest $request) {
      $id = $request->getParameter('id');
      $this->year = $request->getParameter('year');
      $this->month = $request->getParameter('month');
      $this->record_slug = $request->getParameter('record_slug');
      $user_id = $this->getUser()->getGuardUser()->getId();

      $this->forward404Unless($id);
      $this->forward404Unless($this->year);
      $this->forward404Unless($this->month);
      $this->forward404Unless($this->record_slug);

      $currentComment = Doctrine::getTable('Comment')->getComment($id, $this->record_slug, $user_id)->fetchOne();
      $this->forward404Unless($currentComment);

      $this->form = new EditCommentForm($currentComment);
      $this->form->setDefault('body', $currentComment['body']);

      isicsBreadcrumbs::getInstance()->addItem('Editer ce commentaire', '#');
      $response = $this->getResponse();
      Utils::setSlogTitle('Editer ce commentaire', $response);

      if ($request->isMethod('post')) {
          $values = $request->getParameter($this->form->getName());
          $this->form->bind($values);

          if($this->form->isValid()){
              $this->form->save();

              if($currentComment['record_model'] == 'News'){
                $this->redirect('@news_show_detail?year='.$this->year.'&month='.$this->month.'&title_slug='.$this->record_slug);
              }else{
                $this->redirect('@event_show_detail?year='.$this->year.'&month='.$this->month.'&title_slug='.$this->record_slug);
              }
          }
      }
  }
}